﻿
using Models.Common;
using Models.JsonResultModel;
using Newtonsoft.Json;
using System.Linq;

namespace UtilsBase
{
    /// <summary>
    /// Json帮助类
    /// </summary>
    public class RespResult
    {
        // public string respCode { get; set; }
        //public string respMsg { get; set; }
        public RespResult()
        {
            // respCode = "";
            //respMsg = "";
        }

        /// <summary>
        /// 成功返回，实体类数据调用
        /// </summary>
        /// <param name="rtnData"></param>
        /// <returns></returns>
        public static RespResultData Sucess(object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = ResponseCode.SUCCESS,
                respMsg = ResponseCode.SUCCESS_MSG,
                data = rtnData ?? string.Empty
            };
            //JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();
            //jsonSerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
            return RespResultData;
        }
        /// <summary>
        /// Datatable时，调用，js获取用JSON.parse(result).data;
        /// </summary>
        /// <param name="rtnData"></param>
        /// <returns></returns>
        public static string SucessDataTable(object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = ResponseCode.SUCCESS,
                respMsg = ResponseCode.SUCCESS_MSG,
                data = rtnData ?? string.Empty
            };
            return JsonConvert.SerializeObject(RespResultData);
        }
        //错误返回
        public static RespResultData Faild(string responseMessage = "", string responseCode = null, object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = responseCode ?? ResponseCode.System_ERROR,
                respMsg = responseMessage ?? string.Empty,
                data = rtnData ?? string.Empty
            };
            return RespResultData;
        }

        public static RespResultData Faild(object rtnData)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode =  ResponseCode.System_ERROR,
                respMsg = ResponseCode.System_ERROR_MSG,
                data = rtnData ?? string.Empty
            };
            return RespResultData;
        }

        public static RespResultData NotAuthorize(string responseMessage = "", object rtnData = null)
        {
            RespResultData RespResultData = new RespResultData()
            {
                respCode = ResponseCode.NOT_GRANT,
                respMsg = responseMessage ?? ResponseCode.NOT_GRANT_MSG,

                data = rtnData ?? string.Empty
            };
            return RespResultData;
        }


    }
}